package com.hucheng.order.entity;

import com.hucheng.order.dto.CartDTO;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;

import java.sql.Timestamp;

/**
 * @Author: 凉白开不加冰
 * @Version: 0.0.1V
 * @Date: 2019-06-25
 * @Description: 持久层数据
 **/
@Data
public class CartDO {
    private Integer cartId;
    private Integer userId;
    private Integer goodsId;
    private Integer goodsNumber;
    private Integer isDel;
    private Timestamp dateCreated;
    private Timestamp dateUpdated;

    public static CartDO buildCartDO(final CartDTO cartDTO) {
        if (cartDTO != null) {
            CartDO cartDO = new CartDO();
            Timestamp currentTime = new Timestamp(System.currentTimeMillis());
            if (StringUtils.isNotEmpty(cartDTO.getCartId()+"")) {
                cartDO.setCartId(cartDTO.getCartId());
                cartDO.setDateCreated(currentTime);
            }else{
                cartDO.setDateUpdated(currentTime);
            }
            cartDO.setUserId(cartDTO.getUserId());
            cartDO.setGoodsId(cartDTO.getGoodsId());
            cartDO.setGoodsNumber(cartDTO.getGoodsNumber());
            cartDO.setIsDel(0);
            return cartDO;
        }
        return null;
    }
}
